import UIKit

var str = "Hello, playground"


func sum(a:Int,b:Int)->Int{
    return a+b
}

var num = sum(a: 10, b: 20)
print(num)

//返回多个值
func sum_2(a:Int,b:Int)->(a:Int,b:Int,sum:Int){
  return (a,b,a+b)
}

var num_2 = sum_2(a: 10, b: 20)
print("a=\(num_2.a) b=\(num_2.b) a+b=\(num_2.sum)")


//可选参数
func sum_3(a:Int = 10,b:Int=20){
    print(a+b)
}

sum_3(a:60)

//不定数量参数
func sum_4(num:Int...)->Int{
    var sum = 0
    for i in num{
        sum+=i
    }
    return sum
}

var num_4 = sum_4(num: 1,2,3,4,5,6,7,8,9,10)
print(num_4)


func sum_5(a: inout Int,b:Int)->Int{
    a = 20
    return a+b
}

var a = 10
print(sum_5(a:&a,b:60))

//打印：80

//声明一个函数变量,作为函数的参数进行传递
func sum_6(a:Int,b:Int,addFunc:(Int,Int)->Void){
    addFunc(a,b)
}

//调用函数变量，作为回调函数
sum_6(a: 10, b: 20) { (a, b) in
    print(a+b)
}



